var trackPage = function () {
  function e() {
    $.when(n("devices/tracking")).done(function (e) {
      0 === e.errcode && e.data && e.data[0] ? (p = e.data[0], a()) : goome.wx.utils.showTip(e)
    }), i()
  }

  function n(e) {
    return A.imeis = h, $.ajax({
      url: goome.wx.config.apiUrl + e,
      data: A,
      dataType: "jsonp",
      success: function () {},
      error: function (e) {
        goome.wx.utils.showTip(e)
      }
    })
  }

  function a() {
    var e = new BMap.Point(p.lng, p.lat);
    if (!u) {
      o(p);
      var n = new BMap.Icon("images/icon_original_marker.png", new BMap.Size(20, 20));
      n.imageSize = new BMap.Size(20, 20), w = new BMap.Marker(e, {
        icon: n
      }), w.setZIndex(-1), f.addOverlay(w)
    }
    t(p), u.setPosition(e), $(u.iconDom).css({
      "-webkit-transform": "rotate(" + p.course + "deg)",
      transform: "rotate(" + p.course + "deg)"
    });
    var a = g.getPath();
    a.push(e), g.setPath(a), M.open(u.getPosition()), _ && (_ = !1, f.centerAndZoom(u.getPosition(), 13), M.disableAutoPan())
  }

  function t(e) {
    var n = goome.wx.config.status[e.device_info_new] + (0 == e.device_info_new ? e.speed + " km/h" : "");
    v.find(".status").text(n), v.find(".name").text(m), v.find(".info-btn").attr("href", "info.html?" + goome.wx.utils.serialize() + "&imei=" + e.imei + "&lng=" + e.lng + "&lat=" + e.lat), goome.wx.utils.getAddress(e.lng, e.lat, function (e) {
      v.find(".address").text(e), v.height(v.find(".content").height())
    }), O.find(".time").text(goome.wx.utils.dateFormat(e.gps_time) || ""), O.find(".name").text(e.name || "")
  }

  function o(e) {
    var n = 0 == e.device_info_new ? "car_green.png" : "car_gray.png";
    u = new BMap.Marker(new BMap.Point(e.lng, e.lat), {
      icon: new BMap.Icon("images/" + n, new BMap.Size(32, 32))
    }), $(u.iconDom).css({
      "-webkit-transform": "rotate(" + e.course + "deg)",
      transform: "rotate(" + e.course + "deg)"
    }), u.setZIndex(9), f.addOverlay(u)
  }

  function i() {
    clearInterval(P), B = x / 1e3, S.html(B), P = setInterval(function () {
      B > 0 ? S.html(B) : (clearInterval(P), e()), B--
    }, 1e3)
  }

  function s() {
    clearInterval(P)
  }

  function r() {
    b.height($(window).height() - I)
  }

  function l() {
    var e = new BMap.Point(113.920787, 22.573978);
    f = new BMap.Map("map-container"), f.centerAndZoom(e, 5), f.addControl(new BMap.NavigationControl({
      anchor: BMAP_ANCHOR_TOP_RIGHT,
      type: BMAP_NAVIGATION_CONTROL_ZOOM,
      offset: new BMap.Size(0, 70)
    })), f.addControl(new BMap.ScaleControl({
      anchor: BMAP_ANCHOR_TOP_LEFT,
      offset: new BMap.Size(0, 40)
    })), f.addControl(new BMap.MapTypeControl({
      mapTypes: [BMAP_NORMAL_MAP, BMAP_SATELLITE_MAP],
      offset: new BMap.Size(0, 35)
    })), f.enableScrollWheelZoom(!0), g = new BMap.Polyline([], {
      strokeColor: "#00FF00",
      strokeWeight: 4,
      strokeOpacity: .8
    }), f.addOverlay(g);
    var n = '<div class="info-window-container"><div class="arrow"></div><a class="info-btn" href="javascript:;"></a><ul class="content"><li><span class="name"></span></li><li>' + wxLang.status + ': <span class="status"></span></li><li>' + wxLang.address + ': <span class="address"></span></li></ul></div>';
    v = $(n), M = new BMapLib.InfoBox(f, v[0], {
      offset: new BMap.Size(0, 20),
      enableAutoPan: !0,
      align: INFOBOX_AT_TOP,
      closeIconUrl: "images/close.png",
      closeIconMargin: "-999px"
    }), v.on("touchstart MSPointerDown pointerdown", "a", function (e) {
      location.href = e.target.href
    })
  }

  function c() {
    C.on("click", function () {
      e()
    }), T.on("click", function () {
      var e = $(this);
      e.data("open") ? (k.hide(), e.data("open", !1)) : (k.show(), e.data("open", !0))
    }), k.on("click", "a", function (e) {
      var n = $(this),
        a = n.attr("class");
      if (n.hasClass("switch")) n.data("pause") ? (n.removeClass("pause").data("pause", !1).find("a").text(wxLang.stopTrack), i()) : (n.addClass("pause").data("pause", !0).find("a").text(wxLang.startTrack), s()), e.preventDefault();
      else {
        var t = 0 == p.device_info_new || 4 == p.device_info_new ? "false" : "true",
          o = goome.wx.utils.serialize(goome.wx.utils.params());
        o += "&lat=" + p.lat + "&lng=" + p.lng + "&offline=" + t, n.attr("href", a + ".html?" + o)
      }
    })
  }

  function d() {
    c(), r(), l(), e()
  }
  var f = null,
    p = [],
    u = null,
    g = null,
    w = null,
    m = decodeURIComponent(goome.wx.utils.params().name) || "",
    h = goome.wx.utils.params().imei || "",
    M = null,
    v = null,
    _ = !0,
    x = 1e4,
    B = x / 1e3,
    P = null,
    A = goome.wx.utils.defaultParams(),
    I = $(".header").height(),
    O = $(".info-bar"),
    T = $("#menu-btn"),
    k = $("#menu"),
    C = $(".refresh-btn"),
    S = $(".countdown .seconds", O),
    b = $("#map-container");
  return A.map_type = "BAIDU", {
    init: d
  }
}();